const innerAudioContext = wx.createInnerAudioContext();
const db = wx.cloud.database();
Page({
  data: {
    question:null,
    word:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let question = JSON.parse(options.data);

    this.setData({
      question: question
    });

    let word = question.word;
    //查询单词
    if (this.isWord(word)) {
      db.collection('words').where({
        word: word
      }).get().then(res => {

        that.setData({
          word:res.data[0]
        });
      });
    } else {
      db.collection('word_phrase').where({
        word: word
      }).get().then(res => {
        that.setData({
          word: res.data[0]
          
        });
      });
    }


  },

  //是否是单词
  isWord: function (word) {
    //如果有空格说明是词组
    if (word.search(" ") != -1) {
      return false;
    }
    return true;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})